#include <iostream>
#include <string>
using namespace std;

string::size_type find_char(const string &s, char c, int &occur) {
    auto len = s.size();
    auto ret = len;
    for(decltype(ret) i = 0; i != len; i++) {
        if (s[i] == c) {
            if (ret == len) ret = i;
            occur++;
        }
    }

    return ret;
}
int main() {

    string str("Hello world");
    int occur = 0;
    char ch = 'l';
    int idx = find_char(str, 'l', occur);
    cout << "\"" << str << "\" 字符 '" << ch 
        << "' 第一次出现的索引：" << idx 
        << "，共出现了 " << occur << " 次" << endl;
    return 0;
}